<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
	abstract class Element{
	
		protected $_contents = null;
		protected $attributes = null;
		private $_comment = null;

		private static $_options = array('linebreak'=>"\12", 'onmouseout'=>'', 'onmouseover'=>'', 'onclick'=>'', 'onkeydown'=>'', 'onkeyup'=>'');

		protected static function nl(){
			return self::$_options['linebreak'];
		}

	    protected static function setOption($name, $value){
			$linebreaks = array('win' => "\15\12", 'unix' => "\12", 'mac' => "\15");
			if ('linebreak' == $name && isset($linebreaks[$value])) {
				$value = $linebreaks[$value];
			}
			self::$_options[$name] = $value;
		}

		protected static function getOption($name){
			return isset(self::$_options[$name])? self::$_options[$name]: null;
		}

		protected static function optionsToString(){
			$option_string = "";
			$opt_count = count(self::$_options);
			foreach (self::$_options as $name => $value){
				if('linebreak' != $name && '' != $value){
					$option_string .= " ".$name."=\"".$value."\"";
				}
			}
			return $option_string;
		}

		public function setContents($text){
			$this->_contents = $text;
		}

		public function setAttribute($name, $value){
			$this->attributes[$name]=$value;
		}

		public function getAttribute($name){
			return isset($this->attributes[$name])? $this->attributes[$name]: null;
		}

		public function setComment($comment){
			$this->_comment = $comment;
			return $this;
		}

		public function getComment(){
			return $this->_comment;
		}

		abstract public function toString();

		public function getContents(){
			return $this->_contents;
		}

		public function writeOutElement(){
			if($this->getComment() != "")
				echo "<!--".$this->getComment()."-->".$this->writeNewline();
			echo $this->toString();
		}
	}
?>
